<template>
  <view>
     <ls-loading :text="$t('book.sjyzq')+'...'" animation="twinkle" v-show="pageLoading" ></ls-loading>
    
      <FatFatMengSwiper :SwiperImglist="list.BannerArr" @flags="flag"></FatFatMengSwiper>
      <yuan @flags="getdata" ref="yuans"></yuan>  
    <view class="ptb ">
 
      <view class="plr bgs">

        <view class="gridSm g2">
          <view class="item" @click="msg('qdlist?type=male')">
              <view class="flex pd10 rds5" style="background-color: #EDEEFF;">
                <view class="cover">
                  <view class="fz16 bold">男频</view>
                  <view class="fz12" style="color:#6F7492;">{{$t('book.rmhs')}}</view>
                </view>
              </view>
          </view>
       <view class="item" @click="msg('qdlist?type=female')">
              <view class="flex pd10 rds5" style="background-color: #FFEBEC;">
                <view class="cover">
                  <view class="fz16 bold">女频</view> 
                  <view class="fz12" style="color:#896362;">{{$t('book.gyxq')}}</view>
                </view>
              </view>
          </view>
        </view>
      </view> 
      <view class="plr">
        <!-- 标题 -->
        <block v-if="list.NewArr" >
          <uni-title :data="{name:$t('book.xsqx')}"></uni-title>
          <view class="gridSm g1 bg">
            <uni-books-block :data="item" v-for="(item,index) in list.NewArr" :key="index" @flags="flag"></uni-books-block>
          </view>
        </block>

        <block v-for="(it,index) in titledata" :key="index"  class="bg">
          <uni-title :data="it"></uni-title>
          <view class="gridSm g4 bg">
            <view class="item" v-for="(book,bindex) in list.BookArr" :key="bindex"
              v-if="it.id*8-8 <= bindex && bindex< (it.id)*8">
              <uni-books :data="book" :showCategory="false" :showRate="true" @flags="flag"></uni-books>
            </view>
          </view>
        </block>

      </view>
	  <view class="plr">
	   <uni-title :data="{name:'为你推荐'}" v-if="catlist.length>0"></uni-title>
		<view class="gridSm g1 bg" v-if="catlist.length>0">
        <uni-books-pai :data="item" v-for="(item,index) in catlist" :key="index" @flags="flag"></uni-books-pai>
      </view>
	  </view>
    </view>
 <custom-tab-bar :currentTab="currentTab"></custom-tab-bar>
  </view>
</template>

<script>
  import _tool from '@/util/tools.js';
    import _list from '@/util/list.js';
	import _pc from '@/util/pc.js';
  import FatFatMengSwiper from '@/components/FatFatMeng-Swiper/FatFatMeng-Swiper.vue'
  import customTabBar from '@/components/customTabBar.vue';
  
  export default {
    components: {
      FatFatMengSwiper,
	  customTabBar
    },
    data() {
      return {
        channel: uni.getStorageSync("baker_channel"),
		currentTab:'/pages/index/index',
        titledata: [{
          id: 1,
          name: this.$t('book.cxb'),
        }, {
          id: 2,
          name: this.$t('book.fyb'),
        }, {
          id: 3,
          name: this.$t('book.qyb'),
        }, {
          id: 4,
          name: this.$t('book.tjb'),
        }],
        list: {},
        listdata: {
          data: {},
          list: []
        },
        current: 0,
        pageLoading:true,
		catlist:[],
		page:1,
		limit:20,
		sum:0
      }
    },
    onShow() {
		uni.setStorageSync('adis',0)
		_pc.system()
		// #ifdef MP || H5
		uni.setStorageSync('adis',0)
		this.get(this.Httpus+'/index.php?s=Home-Ad-config')
		//this.get(this.Httpus)
		// #endif
      if(uni.getStorageSync('books_data')){
        this.list = uni.getStorageSync('books_data');
        this.pageLoading=false
      }
      this.getdata()
      this.$nextTick(()=>{
        this.$refs.yuans.onChange(1) 
      })  
    },
	onShareAppMessage(res) {
	    
	    return {
	      title: '阅读-免费小说畅读',
	      path: '/pages/index/index'
	    }
	},
	onShareTimeline(){
		return {
		  title: '阅读-免费小说畅读',
		  query: '/pages/bookshelf/index',
		  imageUrl:'https://bookcover.yuewen.com/qdbimg/349573/1031777108/150.jpg'
		}
	},
	onReachBottom(){
	  this.page=this.page+1
	  this.popup()
	  console.log(this.page)
	},
    methods: {
      change(e) {
        this.current = e.detail.current;
      },
	  get(url) {
	  	console.log('chufa',url)
	  	let _this=this;
	  	this.zaiApi({
	  		url: url,
	  	}).then((res) => {
	  		
	  		
	  		if (res.book_source_book) {
	  			
	  			_this.zaiApi({
	  				url: res.book_source_book,
	  			}).then(ress => {
	  				uni.setStorageSync('shuyuan', ress)
	  			}).catch(err => {
	  				
	  			});
	  			_this.zaiApi({
	  				url: res.book_source_yuan,
	  			}).then(ress => {
	  				uni.setStorageSync('shukudata', ress)
	  			}).catch(err => {
	  				
	  			});
	  		}
	  		_this.config = res;
	  		
	  		uni.setStorageSync('config', res);
	  		
	  	}).catch(err => {
	  		
	  		
	  		if(this.sum<=6){
	  		this.get('https://www.ms17.cn/ld/yd.json')
	  		}
	  		this.sum=this.sum+1
	  console.log('chufa')
	  	
	  	});
	  },
      msg(msg){
        uni.navigateTo({
        	url: '/pages/index/'+msg
        });
      },
      flag(e){
		
		 let name=e.name?e.name:e.resourceName
        uni.navigateTo({
        	url: '/pages/book_mall/details?type=list&name='+name
        });
      },
	  popup() {
	     let _this=this;
	  		
	  		
	  _list.categories(1501,'',this.page,this.limit,'','').then((res) => { 
	  		
	     if(this.page>1){
	     _this.catlist=_this.catlist.concat(res);
	     }else{
	     _this.catlist=res?res:[]; 
	     }
	  });
	  
	   },
      getdata() {
        let data=uni.getStorageSync('shukudata');
        if(!data.shu_url){
          this.pageLoading=false
        }
		this.list={"NewArr":[{"id":"1036099286","name":"大明国师","img":"//bookcover.yuewen.com/qdbimg/349573/1036099286/150","intro":"【狱中讲课，朱棣偷听后求我当国师】见证了靖难之役结束，作为“诛十族”对象的姜星火终于松了口气。身为资深穿越者，九世穿越即可回现代永生。自觉马上大功告成的姜星火，无聊到开始在狱中讲课，但似乎渐渐不对劲了起来……马三宝：《海权论》里的大航海时代是什么？姚广孝：《国运论》竟然是传说中的屠龙术！朱高炽：《华夏货币史》的银本位没讲完呐。姜星火：“我明天就要砍头了，剩下的课托梦给你们讲吧。”这时，诏狱的墙壁轰然倒塌，一个声音传来。“姜先生，朕是朱棣，求您当国师吧！”","categoryName":"历史","font":"51.95万字","dec":"连载中"},{"id":"1036056564","name":"让你当兵戒网瘾，你成军官了","img":"//bookcover.yuewen.com/qdbimg/349573/1036056564/150","intro":"重生零九年，只是这个重生姿势貌似有点不对。这一世，家庭富裕，王野网瘾成性，高考前一天都能通宵。无奈，王爸决定送王野去部队当兵戒网瘾。两年后...当王爸视频和儿子打电话，准备问他什么时候退伍回来继承家业的时候。一身军官制服的王野，直接让王爸错愕不已。“爸，我准备在部队一直干了，那什么，家业方面，你要不和妈考虑考虑再生一个？”.......","categoryName":"都市","font":"44.24万字","dec":"连载中"},{"id":"1036010291","name":"乱世书","img":"//bookcover.yuewen.com/qdbimg/349573/1036010291/150","intro":"仗剑江湖载酒行，楚腰纤细掌中轻。少年肩扛长刀，腰间挂酒，大步前行，心中的江湖却隐约难见。乱世书中翻一页，江湖夜雨数十年。蓦然回首，已劈碎了人间。","categoryName":"玄幻","font":"47.54万字","dec":"连载中"}],"bookArr":[],"BookArr":[{"id":"1031940621","name":"灵境行者","img":"//bookcover.yuewen.com/qdbimg/349573/1031940621/150"},{"id":"1027339371","name":"深空彼岸","img":"//bookcover.yuewen.com/qdbimg/349573/1027339371/150"},{"id":"1031777108","name":"光阴之外","img":"//bookcover.yuewen.com/qdbimg/349573/1031777108/150"},{"id":"1010868264","name":"诡秘之主","img":"//bookcover.yuewen.com/qdbimg/349573/1010868264/150"},{"id":"1029391348","name":"这游戏也太真实了","img":"//bookcover.yuewen.com/qdbimg/349573/1029391348/150"},{"id":"1030870265","name":"明克街13号","img":"//bookcover.yuewen.com/qdbimg/349573/1030870265/150"},{"id":"1031794030","name":"道诡异仙","img":"//bookcover.yuewen.com/qdbimg/349573/1031794030/150"},{"id":"1016530091","name":"赤心巡天","img":"//bookcover.yuewen.com/qdbimg/349573/1016530091/150"},{"id":"1036099286","name":"大明国师","img":"//bookcover.yuewen.com/qdbimg/349573/1036099286/150"},{"id":"1034360760","name":"深海余烬","img":"//bookcover.yuewen.com/qdbimg/349573/1034360760/150"},{"id":"1036170277","name":"我本无意成仙","img":"//bookcover.yuewen.com/qdbimg/349573/1036170277/150"},{"id":"1036305137","name":"苟在妖武乱世修仙","img":"//bookcover.yuewen.com/qdbimg/349573/1036305137/150"},{"id":"1036346295","name":"我说了我会时光倒流","img":"//bookcover.yuewen.com/qdbimg/349573/1036346295/150"},{"id":"1036316540","name":"暮年修仙的我长生不死","img":"//bookcover.yuewen.com/qdbimg/349573/1036316540/150"},{"id":"1036283081","name":"港岛旧事","img":"//bookcover.yuewen.com/qdbimg/349573/1036283081/150"},{"id":"1036077914","name":"下班，然后变成魔法少女","img":"//bookcover.yuewen.com/qdbimg/349573/1036077914/150"},{"id":"1036123091","name":"邻家今天也很可爱","img":"//bookcover.yuewen.com/qdbimg/349573/1036123091/150"},{"id":"1036124603","name":"辞职后我成了神","img":"//bookcover.yuewen.com/qdbimg/349573/1036124603/150"},{"id":"1036102799","name":"仙玉问道","img":"//bookcover.yuewen.com/qdbimg/349573/1036102799/150"},{"id":"1036217976","name":"战锤：我不要成为臭罐头啊！！！","img":"//bookcover.yuewen.com/qdbimg/349573/1036217976/150"},{"id":"1036370336","name":"宿命之环","img":"//bookcover.yuewen.com/qdbimg/349573/1036370336/150"},{"id":"1036504904","name":"谁让他修仙的！","img":"//bookcover.yuewen.com/qdbimg/349573/1036504904/150"},{"id":"1036484427","name":"我为长生仙","img":"//bookcover.yuewen.com/qdbimg/349573/1036484427/150"},{"id":"1036370467","name":"全球每月一个新规则","img":"//bookcover.yuewen.com/qdbimg/349573/1036370467/150"},{"id":"1034888747","name":"父可敌国","img":"//bookcover.yuewen.com/qdbimg/349573/1034888747/150"},{"id":"1036314249","name":"兼职艺术家","img":"//bookcover.yuewen.com/qdbimg/349573/1036314249/150"},{"id":"1036314541","name":"妖女住手","img":"//bookcover.yuewen.com/qdbimg/349573/1036314541/150"},{"id":"1036372013","name":"神秘尽头","img":"//bookcover.yuewen.com/qdbimg/349573/1036372013/150"},{"id":"1036378142","name":"重生09做男神","img":"//bookcover.yuewen.com/qdbimg/349573/1036378142/150"},{"id":"1036348237","name":"登顶全球：我真的不是天才","img":"//bookcover.yuewen.com/qdbimg/349573/1036348237/150"},{"id":"1024121691","name":"保护我方族长","img":"//bookcover.yuewen.com/qdbimg/349573/1024121691/150"},{"id":"1036370336","name":"宿命之环","img":"//bookcover.yuewen.com/qdbimg/349573/1036370336/150"},{"id":"1035234205","name":"天衍遗录","img":"//bookcover.yuewen.com/qdbimg/349573/1035234205/150"},{"id":"1017331719","name":"青葫剑仙","img":"//bookcover.yuewen.com/qdbimg/349573/1017331719/150"},{"id":"1028893533","name":"嘉佑嬉事","img":"//bookcover.yuewen.com/qdbimg/349573/1028893533/150"},{"id":"1027339371","name":"深空彼岸","img":"//bookcover.yuewen.com/qdbimg/349573/1027339371/150"},{"id":"1034419446","name":"机武风暴","img":"//bookcover.yuewen.com/qdbimg/349573/1034419446/150"},{"id":"1031940621","name":"灵境行者","img":"//bookcover.yuewen.com/qdbimg/349573/1031940621/150"},{"id":"1032778366","name":"择日飞升","img":"//bookcover.yuewen.com/qdbimg/349573/1032778366/150"},{"id":"1031777108","name":"光阴之外","img":"//bookcover.yuewen.com/qdbimg/349573/1031777108/150"}],"BannerArr":[{"image":"//bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/58e79db165cbda26bf7081d3430fa495.jpg","name":"再造盛唐从召唤玩"},{"image":"//bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/755cd3dac9bc247f61766e0f4af564e8.jpg","name":"刚成仙神，子孙求"},{"image":"//bossaudioandcomic-1252317822.image.myqcloud.com/activity/document/0ad35f42b7ca81d57d92128a2778a234.jpg","name":"这个影帝要加钱"}]}
        this.zaiApi({
          url: data.shu_url,
        }).then((re) => {
		if(re){
          _tool.IndexData(re,data).then((res) => {
			  console.log('res',res)
			  if(res.BookArr.length>0){  
            uni.setStorageSync('books_data',res)
            this.list = res;
			}
			this.popup()
            this.pageLoading=false
          });
		  }
        });
      },
      onChannelChange(e) {
        this.channel = e.detail.value;
        uni.setStorageSync("home_channel", this.channel);
        this.$nextTick(() => {
          this.$refs.page.refresh();
          this.$refs.banner.loadData();
        });
      }
    }
  }
</script>




<style lang="scss">
  @import "common/css/base-view.scss";
page {
		background: #f1f1f1;
		color: #33363A;
	}
  .swiper-box {
    image {
      width: 100%;
      height: 200rpx;
    }
  }
  .bg{
   background-color: #FFFFFF;
   padding: 60rpx 20rpx 0rpx 20rpx;
   margin-bottom: 40rpx;
   border-radius: 10rpx;
  }
  .bgs{
  background-color: #FFFFFF;
  padding: 40rpx 0 20rpx 0;
  margin:-20rpx 20rpx 40rpx 20rpx;
  border-radius: 10rpx;  
  }
  .catlist{
	  margin: 25rpx;
  }
</style>
